package com.example.demo.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DonwloadDoctorLicense {


    public static void main(String[] args) throws FileNotFoundException {
        String[] headerName = {"account_id","real_name","field_value"};
        String[] headerKey = {"accountId","realName","imageUrl"};
        File file = new File("D:\\5.xlsx");
        List<Map<String, String>> resultlist = ExcelUtils2.praseExcel(new FileInputStream(file),headerName,headerKey);
        final String[] tmpAccountId = {""};
        resultlist.forEach((map) ->{
            try {
                if(map.size()==0){
                    return;
                }
                String dirPath = "D:"+File.separator+"doctorLicense"+File.separator+map.get("accountId")+"_"+map.get("realName");
                if(!tmpAccountId[0].equals(map.get("accountId").toString())){
                    File downDirectory = new File(dirPath);
                    if (!downDirectory.exists()){
                        downDirectory.mkdir();
                    }
                }
                ImageDownload.DownloadFile(map.get("imageUrl").toString(),dirPath);
                tmpAccountId[0] = map.get("accountId").toString();

            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
    }



}
